#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
int a[N], pos[N];
struct Line {
  int l, r;
  int id;
  bool operator<(const Line& b) const { return r < b.r; }
} c[N];
int ans[N];

int sum[N << 2];
void update(int x, int d, int p, int l, int r) {
  if (l == r) {
    sum[p] += d;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, d, p << 1, l, mid);
  else
    update(x, d, p << 1 | 1, mid + 1, r);
  sum[p] = sum[p << 1] + sum[p << 1 | 1];
}
int query(int L, int R, int p, int l, int r) {
  if (L <= l && R >= r) return sum[p];
  int res = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) res += query(L, R, p << 1, l, mid);
  if (R > mid) res += query(L, R, p << 1 | 1, mid + 1, r);
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  cin >> m;
  rep(i, 1, m) c[i].id = i, cin >> c[i].l >> c[i].r;
  sort(c + 1, c + m + 1);
  int r = 0;
  rep(i, 1, m) {
    while (r < c[i].r) {
      ++r;
      int x = a[r];
      int pre = pos[x];
      pos[x] = r;
      if (pre) update(pre, -1, 1, 1, n);  // 撤销旧位置
      update(r, 1, 1, 1, n);              // 更新新位置
    }
    ans[c[i].id] = query(c[i].l, c[i].r, 1, 1, n);
  }
  rep(i, 1, m) cout << ans[i] << endl;
  return 0;
}